import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';
import 'package:flutter_application_1/siginin.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html/html_parser.dart';
import 'package:flutter_html/style.dart';

Map articleData = {};

class ArticlePage extends StatefulWidget {
  final String id;
  // final
  ArticlePage({Key key, this.id}) : super(key: key);

  @override
  _ArticlePageState createState() {
    return _ArticlePageState();
  }
}

class _ArticlePageState extends State<ArticlePage> {
  get() async {
    var httpReq = new HttpClient();
    var url = new Uri.http('192.168.50.19:2000',
        '/oceanAPI/v1/tables/find/default/table_id/${widget.id}', {});
    var request = await httpReq.getUrl(url);
    var res = await request.close();
    var resBody;
    if (res.statusCode == 200) {
      resBody = await res.transform(utf8.decoder).join();
      int status = jsonDecode(resBody)['status'];
      print(status);
      if (status == 200) {
        final Map<String, dynamic> data = jsonDecode(resBody);
        articleData = data['data'];
      }
    } else {}
    // await
    print(articleData);
  }

  Widget build(BuildContext context) {
    get();
    return Scaffold(
      appBar: AppBar(
        title: Text(articleData['table_name']),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.logout),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
        ],
      ),
      body: new Scrollbar(
        child: SingleChildScrollView(
          // padding: EdgeInsets.all(15),
          child: Column(
            children: [
              new Padding(
                padding: EdgeInsets.all(15),
                child: new Text(
                  articleData['table_name'],
                  maxLines: 5,
                  overflow: TextOverflow.ellipsis,
                  style: new TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 20,
                  ),
                ),
              ),
              new Row(
                children: [
                  new Padding(
                    padding: EdgeInsets.all(15),
                    child: TextButton(
                      onPressed: () {},
                      child: new Text(articleData['table_author']),
                      // articleData['table_sign'].map((item) => {new Text(item)}),
                    ),
                  ),
                  Spacer(),
                ],
              ),
              new Padding(
                padding: EdgeInsets.all(15),
                child: Html(data: articleData['table_main']),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
